<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="utf-8">
            <title>Cindy JS</title>
            <script type="text/javascript" src="../build/js/Cindy.js"></script>
            </head>

	<body style="font-family:Arial;">

        <h1>Linear Algebra Tests</h1>
<div  style="width:800px; line-height: 1.5">
</div>
        <script id='init' type='text/x-cindyscript'>
        </script>

        <script id='csmove' type='text/x-cindyscript'>
	DD = [[1+i, 2*i, 5],
		[5, 1+i*random(), 3],
		[1, 7+i*random(), 2]];
	println(inverse(DD)*DD);
        n = 100;
        AA=zeromatrix(n,n);
       repeat(n,j,
         repeat(n,k,
           AA_j_k=(random()) + i*(random());
         );
       );


        bb = zerovector(n);
        repeat(n,j, bb_j = random() + i*(random()));

        javascript("var tt; t = Date.now()");
        x = linearsolve(AA,bb);
	println("time for linearsolve");
        javascript("console.log(Date.now()-t)");
	drawtext((-6,6), "linearsolve, inverse and det: x=linearsolve(A,b), x=inv(A)*b, det(A) == LUdet(A)");
        drawtext((-6, 5),"|A*x-b|");
        drawtext((-3, 5),|AA*x-bb|);
 //       println(|AA*x-bb| < 0.0000001);
        javascript("var tt; t = Date.now()");
	invA = inverse(AA);
	println("time for inverse");
        javascript("console.log(Date.now()-t)");
        drawtext((-6, 4),"|A^-1*b-x|");
        drawtext((-3, 4),|invA*bb-x|);
//        println(|(invA*bb)-x|);
//        println(|(inverse(AA)*bb)-x| < 0.0000001);

       repeat(n,j,
         repeat(n,k,
           if(j<k,AA_j_k=0,AA_j_k = AA_j_k +0.25+0.25*i);
         );
       );

	mydet = 1;
	repeat(n, j, mydet = mydet*AA_j_j);
	//println("mydet" +  mydet);
        javascript("var tt; t = Date.now()");
	println("time for det");
	ludet = det(AA);
        javascript("console.log(Date.now()-t)");
//	println("ludet" + ludet);
        drawtext((-6, 3),"|manual det - LUdet|");
        drawtext((-1, 3),|mydet - ludet|);

        drawtext((-6, 2),"LUdet");
        drawtext((-1, 2),ludet);

        </script>



        <div style="position:relative">
        <div  id="CSCanvas" style="width:800px; height:500px; border:2px solid #000000; top:0px; left:0px;"></div>
</div>

        <script type="text/javascript">

            var gslp=[
//                      {name:"O", type:"Free", pos:[0,0],color:[0,0,0],pinned:true,size:3},
//                      {name:"B", type:"Free", pos:[9,1],color:[1,0,0],size:0.01},
//                      {name:"C", type:"Free", pos:[-6,6],color:[1,0,0],size:0.01},
//		      {name:"bc", type:"Join", args:["B","C"],color:[0,0,1]},
//                      {name:"D", type:"PointOnLine", pos:[1,2],args:["bc"],color:[1,0,0],size:3},




                    ];
                     CindyJS({canvasname:"CSCanvas",
                        defaultAppearance: {dimDependent: 0.7},
                        movescript:"csmove",
                        initscript:"init",
                        geometry:gslp,
 //                       grid:1,
//                        snap:true,
                        transform:[{scale:1.5},{translate:[0,0]}],
}
                        );

        </script>
<div  style="width:800px; line-height: 1.5">

</div>
<br>
<br>




	</body>
</html>
